#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
int main()
{
    int t = 0;
    scanf("%d", &t);
    getchar();
    while (t--)
    {
        char ch[80][30] = { 0 };
        int i = 0;
        int num = 0;
        char c = 0;
        while (1)
        {
            scanf("%c", &c);
            if (c == '\n' || c == -1)
                break;
            if (c == ' ')
            {
                ch[i][num] = '\0';
                int left = 0;
                int right = num - 1;
                while (left < right)
                {
                    char ca = ch[i][right];
                    ch[i][right] = ch[i][left];
                    ch[i][left] = ca;
                    left++;
                    right--;
                }
                if (i == 0)
                    printf("%s", ch[i]);
                else
                    printf(" %s", ch[i]);
                i++;
                num = 0;
            }
            else
            {
                ch[i][num] = c;
                num++;
            }
        }
        int left = 0;
        int right = num - 1;
        while (left < right)
        {
            char ca = ch[i][right];
            ch[i][right] = ch[i][left];
            ch[i][left] = ca;
            left++;
            right--;
        }
        if (i == 0)
            printf("%s", ch[i]);
        else
            printf(" %s\n", ch[i]);
        i++;
        num = 0;
    }
    return 0;
}